import { FMVCS } from "../../fgui/fmvc/FMVCS";
import MapLocalVO from "./MapLocalVO";
import { ConstDefine } from "../common/ConstDefine";
import PlayerCtrl from "../player/PlayerCtrl";
import { GlobalEvent } from "../global/Global";

export default class MapLocalData extends FMVCS.FData {
    protected _vo: MapLocalVO = new MapLocalVO();
    get vo () {
        return this._vo;
    }

    /** 新增地图 */
    addMap(map: ConstDefine.Config.StarConfig){
        map.id = PlayerCtrl.data.vo.openId + this.vo.instId
        this.vo.mapList.push(map);
        this.vo.instId++;
        this.saveData();
        this.emit(GlobalEvent.UIListenID.UI_GameMapFlush);
    }

    /** 修改地图 */
    rivisionsMap(map: ConstDefine.Config.StarConfig){
        let instId = map.id;
        for(let i = 0; i < this.vo.mapList.length; ++i){
            let tMap = this.vo.mapList[i];
            if(tMap.id == instId){
                this.vo.mapList[i] = map;
                this.saveData();
                this.emit(GlobalEvent.UIListenID.UI_GameMapFlush);
                break;
            }
        }
    }

    /** 删除地图 */
    removeMap(index: number){
        if(index < this.vo.mapList.length){
            this.vo.mapList.splice(index, 1);
            this.saveData();
            this.emit(GlobalEvent.UIListenID.UI_GameMapFlush);
            this.emit(GlobalEvent.UIListenID.UI_ShowTips, `地图删除成功`);
        }
    }
}